package com.caiyigo.baihua.controller;

import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.beetl.ext.servlet.ServletGroupTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
@RequestMapping(value = "layout")
public class LayoutController extends BaseController {
	private static final String TO_PAGE = "to";

	@RequestMapping(value = "/rh", method = { RequestMethod.POST,
			RequestMethod.GET })
	public String rh(@RequestParam(value = TO_PAGE) String to,
			HttpServletRequest request, HttpServletResponse response,
			RedirectAttributes attr) throws UnknownHostException {
		String para = null;
		Enumeration<String> e = request.getParameterNames();
		while (e.hasMoreElements()) {
			para = e.nextElement();
			if (TO_PAGE.equals(para)) {
				continue;
			}
			request.setAttribute(para, URLDecoder.decode(request.getParameter(para)));
		}
		if ("page/index/log".equals(to)) {
			request.setAttribute("systemUrl","访问地址:http://"+InetAddress.getLocalHost().getHostAddress()+":8080"+request.getContextPath());
		}

		return (to);
	}
}
